(function() {
    angular.module('app').controller('productCtrl', productCtrl);

    productCtrl.$inject = ['$rootScope'];

    function productCtrl($rootScope) {
        var vm = this;

        //filter 
        vm.filter = {};

        vm.filterConfig = {
            category: {
                type: ''
            },
            shopType: {},
            title: {},
            sellAmount: {},
            price: {}
        };

        vm.bars = [ 
        {
            text: '销售额',
            default:'销售额',
            sortColumn:'sellMoney',
            sort:'',
            click: function() {

                if(this.text === '销售额'){

                    this.text = "销售额从低到高";
                    this.sort = "up";          

                }else if(this.text === "销售额从低到高"){

                    this.text = "销售额从高到低"; 
                    this.sort = "down";  
                            

                }else{
                    this.text = "销售额从低到高";

                    this.sort = "up";
                    
                  
                }
                $rootScope.$emit('tool-bar-component-$emit-EV',{'sortColumn':'sellMoney','sort':this.sort});

                vm.bars.init(this);
                
            }

        },{
            text: '销量',
            default:'销量',
            sortColumn:'sellAmount',
            sort:'',
            click: function() {

                if(this.text === '销量'){

                    this.text = "销量从低到高";
                    this.sort = "up";                    

                }else if(this.text === "销量从低到高"){

                    this.text = "销量从高到低"; 
                    this.sort = "down";                     

                }else{

                    this.text = "销量从低到高";
                    this.sort = "up";
                    
                }

                $rootScope.$emit('tool-bar-component-$emit-EV',{'sortColumn':'sellMoney','sort':this.sort});

                vm.bars.init(this);
                
            }

        }, {
            type: 'dropdown',
            text: '价格',
            icon: 'fa fa-angle-down',
            show: false,
            menu_item: [{
                text: '价格从低到高',
                value: 'taobao',
                icon: ''
            }, {
                text: '价格从高到低',
                value: 'taobao',
                icon: ''
            }],
            onSelect: function(item,event) {

                console.log('select:');

                this.text = item.text;

                alertM(item.text);

                this.show = false;

                event.stopPropagation();
                event.preventDefault();
            },
            click: function() {
                this.show = !this.show;
            }

        }, {

            type: 'dropdown',
            text: '全网',
            name: 'shopType',
            class: 'clearfix',
            icon: 'fa fa-angle-down',
            show: false,
            menu_item: [{
                text: '全网',
                value: 'taobao',
                icon: ''
            }, {
                text: '淘宝',
                value: 'taobao',
                icon: ''
            }, {
                text: '天猫',
                value: 'taobao',
                icon: ''
            }, {
                text: '全球购',
                value: 'taobao',
                icon: ''
            }, {
                text: '天猫过几',
                value: 'taobao',
                icon: ''
            }],

            onSelect: function(item,event) {

                console.log('select:');

                this.text = item.text;

                alertM(item.text);

                this.show = false;

                event.stopPropagation();
                event.preventDefault();
            },
            click: function() {
                this.show = !this.show;
            }
        }]; 
  
    }
})();
